<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-form [formGroup]="formGroup" class="formGroup" lvKeepRequiredWidth>
  <lv-form-item *ngIf="!isDrill">
    <lv-form-label>
      {{ 'protection_restore_to_label' | i18n }}
    </lv-form-label>
    <lv-form-control>
      <lv-radio-group
        formControlName="restoreTo"
        [lvGroupName]="'restoreToGroup'"
      >
        <lv-group [lvGutter]="'20px'">
          <lv-radio
            [lvValue]="restoreLocationType.ORIGIN"
            [lvDisabled]="disableOriginLocation"
            [lv-tooltip]="
              disableOriginLocation
                ? ('protection_cloud_origin_restore_disabled_label' | i18n)
                : ''
            "
          >
            {{ 'common_restore_to_origin_location_label' | i18n }}
          </lv-radio>
          <lv-radio
            [lvValue]="restoreLocationType.NEW"
            [lvDisabled]=" rowCopy.resource_sub_type ===
        dataMap.Resource_Type.SQLServerClusterInstance.value|| isFileLevelAndClusterRestore"
            [lv-tooltip]="
              disableOriginLocation
                ? ('protection_sqlserver_instance_new_restore_label' | i18n)
                : ''
            "
          >
            {{ 'common_restore_to_new_location_label' | i18n }}
          </lv-radio>
        </lv-group>
      </lv-radio-group>
    </lv-form-control>
  </lv-form-item>
  <ng-container *ngIf="formGroup.value.restoreTo === restoreLocationType.NEW">
    <aui-select-tag [formGroup]="formGroup" (updateTable)="updateTable($event)" [targetKey]="'position'"></aui-select-tag>
  </ng-container>
  <lv-form-item>
    <lv-form-label
      [lvRequired]="formGroup.value.restoreTo === restoreLocationType.NEW"
    >
      {{ locationLabel }}
    </lv-form-label>
    <lv-form-control>
      <lv-select
        formControlName="position"
        [lvOptions]="options"
        lvValueKey="key"
        lvShowFilter
        lvFilterKey="label"
        lvFilterMode="contains"
        [lvDisabled]="formGroup.value.restoreTo === restoreLocationType.ORIGIN"
      >
      </lv-select>
    </lv-form-control>
  </lv-form-item>

  <ng-container *ngIf="(formGroup.value.restoreTo === restoreLocationType.NEW)&&(rowCopy.resource_sub_type ===
        dataMap.Resource_Type.SQLServerInstance.value)&&(!isFileLevelRestore)">
    <lv-form-item>
      <lv-form-label lvRequired>
        {{ 'protection_target_instance_label' | i18n }}
      </lv-form-label>
      <lv-form-control>
        <lv-select
          formControlName="instance"
          [lvOptions]="instanceOptions"
          lvValueKey="key"
          lvShowFilter
          lvFilterKey="label"
          lvFilterMode="contains"
        >
        </lv-select>
      </lv-form-control>
    </lv-form-item>
  </ng-container>
  <div class="aui-tips">
    <i
      lv-icon="lv-icon-status-info"
      lvColorState="true"
      class="type-icon"
    ></i>
    <span class="form-tips">{{
        'protection_close_database_tip_label' | i18n
      }}</span>
  </div>
  <ng-container
    *ngIf="
      formGroup.value.restoreTo === restoreLocationType.NEW &&
      isFileLevelRestore &&
      rowCopy.resource_sub_type !==
        dataMap.Resource_Type.SQLServerInstance.value
    "
  >
    <lv-form-item>
      <lv-form-label lvRequired>
        {{ 'common_destination_path_label' | i18n }}
        <i
          lv-icon="aui-icon-help"
          lv-tooltip="{{ 'protection_target_path_tips_label' | i18n }}"
          lvTooltipTheme="light"
          class="configform-constraint"
          lvColorState="true"
        ></i>
      </lv-form-label>
      <lv-form-control [lvErrorTip]="pathErrorTip">
        <input lv-input type="text" formControlName="path" />
      </lv-form-control>
    </lv-form-item>
  </ng-container>
</lv-form>
